In [1]:
%matplotlib inline
import random
from scipy.stats import bernoulli
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
In [2]:
#Configuration
MAX_NESTING = 4
Allowed Symbols are an integer, representing the current depth, open parenthesis when the max nesting has not been reached and close parenthesis, as long as the current depth is not 0.
In [8]:
teststring = ""
current_depth = 0
for i in xrange(1000000):
if current_depth == 0:
allowed_chars = ["( ", "0 "]
elif current_depth == MAX_NESTING:
allowed_chars = [") ", str(current_depth) + " "]
else:
allowed_chars = [") ", "( ", str(current_depth) + " "]
new_pick = random.choice(allowed_chars)
if new_pick == ") ":
current_depth -=1
elif new_pick == "( ":
current_depth +=1
teststring += new_pick
In [11]:
with open("../data/paren-train.txt", 'w') as f:
f.write(teststring)
In [12]:
teststring = ""
current_depth = 0
for i in xrange(100000):
if current_depth == 0:
allowed_chars = ["( ", "0 "]
elif current_depth == MAX_NESTING:
allowed_chars = [") ", str(current_depth) + " "]
else:
allowed_chars = [") ", "( ", str(current_depth) + " "]
new_pick = random.choice(allowed_chars)
if new_pick == ") ":
current_depth -=1
elif new_pick == "( ":
current_depth +=1
teststring += new_pick
In [13]:
with open("../data/paren-valid.txt", 'w') as f:
f.write(teststring)
In [ ]: